package com.ice_col.surfaceviewturntable;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.view.View;
import android.widget.ImageButton;

import java.util.Random;

public class MainActivity extends AppCompatActivity {

    private ImageButton mStartButton;
    private Turntable mTurntable;


    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        mStartButton=(ImageButton) findViewById(R.id.bt_go);
        mTurntable=(Turntable) findViewById(R.id.turntable);
        mStartButton.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                if (mTurntable.isTurning()) {
                    if (!mTurntable.ismShouldEnd()) {
                        mTurntable.setmStartAngle(0);
                        mTurntable.setShouldEnd(true);
                        mStartButton.setImageResource(R.drawable.center_text);
                    }
                } else {
                    Random random=new Random();
                    int index=random.nextInt(6);
//                    System.out.println("index:"+index);
                    mTurntable.setmSpeed(index);       //控制停止位置
                    mTurntable.setShouldEnd(false);
                    mStartButton.setImageResource(R.drawable.stop);
                }
            }
        });
    }

}
